package com.zmj.sy.mom.srv.aps.service;


import cn.hutool.core.comparator.CompareUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.zmj.sy.mom.srv.aps.bean.dto.orderCompare.OrderCompareDto;
import com.zmj.sy.mom.srv.aps.bean.entity.order.Order;
import com.zmj.sy.mom.srv.aps.bean.entity.third.SinoCamPushDrawing;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseListResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.orderCompare.OrderCompareVo;
import com.zmj.sy.mom.srv.aps.mapper.CompleteReportMapper;
import com.zmj.sy.mom.srv.aps.mapper.OrderCompareMapper;
import com.zmj.sy.mom.srv.aps.mapper.OrderMapper;
import com.zmj.sy.mom.srv.aps.mapper.SinoCamPushDrawingMapper;
import com.zmj.sy.mom.srv.aps.utils.MaterialUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Description: 订单一致性对比
 * @author: hejiahui
 * @since: 2024/9/13 8:49
 */
@RequiredArgsConstructor
@Service
public class OrderCompareService {

    private final OrderCompareMapper baseMapper;
    private final OrderMapper orderMapper;
    private final CompleteReportMapper completeReportMapper;
    private final SinoCamPushDrawingMapper sinoCamPushDrawingMapper;

    /**
     * @Description: 一致性对比
     * @author: hejiahui
     * @since: 2024/9/13 8:50
     */
    public BaseListResVo<OrderCompareVo> getOrderCompare(OrderCompareDto dto) throws Exception {

        List<OrderCompareVo> resultList = new ArrayList<>();
        //获取订单下顶级物料
        List<String> topOrderList = new ArrayList<>();
        //三大件
        /*QueryWrapper<Order> threePieceQuery = new QueryWrapper<>();
        threePieceQuery.eq("order_type", 1);
        threePieceQuery.eq("construct_no", dto.getOrderNo());
        threePieceQuery.apply("mater_code <> serial_code");
        List<Order> threePieceOrders = orderMapper.selectList(threePieceQuery);*/
        List<String> threePieceOrders = orderMapper.selectThreePiece(dto.getOrderNo());
        if (ObjectUtils.isNotEmpty(threePieceOrders)) {
            topOrderList.addAll(threePieceOrders);
        }
        //侧护板
        topOrderList.addAll(orderMapper.selectCeban(dto.getOrderNo()));

        if (ObjectUtils.isEmpty(topOrderList)) {
            return BaseListResVo.empty();
        }

        //获取erp订单bom
        QueryWrapper<?> erpBomQuery = new QueryWrapper<>();
        erpBomQuery.eq("ord.order_code", dto.getOrderNo());
        List<Map<String, Object>> erpOrderBomList = baseMapper.getErpOrderBom(erpBomQuery);
        //获取套料订单bom
//        List<SinoCamPushDrawing> nestOrderList = sinoCamPushDrawingMapper.lambdaQuery().eq(SinoCamPushDrawing::getProductId, dto.getOrderNo()).list();
        QueryWrapper<?> nestBomQuery = new QueryWrapper<>();
        nestBomQuery.eq("pdr.project_id", dto.getOrderNo());
        List<Map<String, Object>> nestOrderList = baseMapper.getNestBom(nestBomQuery);
        //数据对比
        List<String> source = new ArrayList<>();
        source.add(dto.getCompareSource1());
        source.add(dto.getCompareSource2());

        if (source.contains("ERP") && source.contains("aps订单")) {
            //获取aps订单bom
            QueryWrapper<?> apsBomQuery = new QueryWrapper<>();
            apsBomQuery.eq("ord.order_code", dto.getOrderNo());
            List<Map<String, Object>> apsOrderBomList = completeReportMapper.getOrderBom2(apsBomQuery);
            resultList = this.compareErpApsOrder(topOrderList, apsOrderBomList, erpOrderBomList);
        } else if (source.contains("aps订单") && source.contains("aps套料")) {
            //获取aps订单bom
            QueryWrapper<?> apsBomQuery = new QueryWrapper<>();
            apsBomQuery.eq("ord.order_code", dto.getOrderNo());
            List<Map<String, Object>> apsOrderBomList = completeReportMapper.getOrderBom(apsBomQuery);
            resultList = this.compareApsNestOrder(topOrderList,apsOrderBomList,nestOrderList);
        } else if (source.contains("aps套料") && source.contains("ERP")) {
            resultList = this.compareNestErpOrder(topOrderList,nestOrderList,erpOrderBomList);
        } else {
            throw new Exception("请选择正确的对比来源");
        }

        return new BaseListResVo<>(resultList);
    }
    /**
     * @Description: aps订单与ERP对比
     *
     * @author: hejiahui
     * @since: 2024/9/13 10:46
     */
    private List<OrderCompareVo> compareErpApsOrder(List<String> topOrderList, List<Map<String, Object>> apsOrderBomList, List<Map<String, Object>> erpOrderBomList) {
        List<OrderCompareVo> resultList = new ArrayList<>();
        Map<String, List<Map<String, Object>>> apsMaterCodeMap = apsOrderBomList.stream().collect(Collectors.groupingBy(e -> e.get("mater_code").toString()));
        Map<String, List<Map<String, Object>>> apsBomIdMap = apsOrderBomList.stream().filter(e -> e.get("pid") != null ).collect(Collectors.groupingBy(e -> (String) e.get("pid")));
        Map<String, List<Map<String, Object>>> erpGraphNoMap = erpOrderBomList.stream().collect(Collectors.groupingBy(e -> e.get("graph_no").toString()));
        Map<String, List<Map<String, Object>>> erpMaterCodeMap = erpOrderBomList.stream().filter(e -> e.get("pm_code") != null).collect(Collectors.groupingBy(e -> e.get("pm_code").toString()));

        for (String order : topOrderList) {
            List<Map<String, Object>> aps = apsMaterCodeMap.get(order);
            List<Map<String, Object>> erp = erpGraphNoMap.get(order);
            if (ObjectUtils.isEmpty(aps) || ObjectUtils.isEmpty(erp)) {
                throw new RuntimeException("数据异常:未找到" + order + "的数据！！！");
            } else if (aps.size() > 1 || erp.size() > 1) {
                throw new RuntimeException(order + "的数据" + "找到多条！！！");
            }
            //获取aps全量bom
            List<Map<String, Object>> oldtotalApsBomList = new ArrayList<>();
            oldtotalApsBomList.add(aps.get(0));
            List<Map<String, Object>> apsCheckList = new ArrayList<>();
            apsCheckList.add(aps.get(0));
            while (apsCheckList.size() > 0) {
                Map<String, Object> apsBom = apsCheckList.get(0);
                List<Map<String, Object>> maps = apsBomIdMap.get((String) apsBom.get("id"));
                apsCheckList.remove(0);
                if (ObjectUtils.isNotEmpty(maps)) {
                    oldtotalApsBomList.addAll(maps);
                    apsCheckList.addAll(maps);
                }
            }
            //合并共用件
            List<Map<String, Object>> totalApsBomList = new ArrayList<>();
            final Map<String, List<Map<String, Object>>> apsMaterialCodeMap = oldtotalApsBomList.stream().collect(Collectors.groupingBy(e -> e.get("erp_code").toString()));
            for (String key : apsMaterialCodeMap.keySet()) {
                List<Map<String, Object>> apsBoms = apsMaterialCodeMap.get(key);
                if (apsBoms.size() > 1) {
                    final Set<String> set = apsBoms.stream().map(e -> e.get("erp_code").toString() + e.get("pid").toString()).collect(Collectors.toSet());
                    if (set.size() > 1) {
                        Map<String, Object> erpBom = new HashMap<>();
                        erpBom  = apsBoms.stream().max(Comparator.comparing(e -> e.get("pid").toString())).get();
                        final int totalCnt = apsBoms.stream().mapToInt(e ->new BigDecimal(e.get("totalCount").toString()).intValue()).sum();
                        erpBom.put("totalCount", totalCnt);
                        totalApsBomList.add(erpBom);
                    } else {
                        totalApsBomList.add(apsBoms.get(0));
                    }
                } else {
                    totalApsBomList.addAll(apsBoms);
                }
            }
            //获取erp全量bom
            List<Map<String, Object>> oldTotalErpBomList = new ArrayList<>();
            oldTotalErpBomList.add(erp.get(0));
            List<Map<String, Object>> erpCheckList = new ArrayList<>();
            erpCheckList.add(erp.get(0));
            while (erpCheckList.size() > 0) {
                Map<String, Object> erpBom = erpCheckList.get(0);
                List<Map<String, Object>> maps = erpMaterCodeMap.get(erpBom.get("material_code").toString());
                erpCheckList.remove(0);
                if (ObjectUtils.isNotEmpty(maps)) {
                    oldTotalErpBomList.addAll(maps);
                    erpCheckList.addAll(maps);
                }
            }
            //合并共用件
            List<Map<String, Object>> totalErpBomList = new ArrayList<>();
            final Map<String, List<Map<String, Object>>> materialCodeMap = oldTotalErpBomList.stream().collect(Collectors.groupingBy(e -> e.get("material_code").toString()));
            for (String materialCode : materialCodeMap.keySet()) {
                List<Map<String, Object>> erpBomList = materialCodeMap.get(materialCode);
                if (erpBomList.size() > 1) {
                    final Set<String> set = erpBomList.stream().map(e -> e.get("pm_code").toString() + e.get("material_code").toString()).collect(Collectors.toSet());
                    if (set.size() > 1) {
                        Map<String, Object> erpBom = new HashMap<>();
                        erpBom  = erpBomList.stream().max(Comparator.comparing(e -> e.get("pm_code").toString())).get();
                        final int totalCnt = erpBomList.stream().mapToInt(e -> Integer.parseInt(e.get("req_qty").toString())).sum();
                        erpBom.put("req_qty", totalCnt);
                        totalErpBomList.add(erpBom);
                    } else {
                        totalErpBomList.add(erpBomList.get(0));
                    }
                } else {
                    totalErpBomList.addAll(erpBomList);
                }
            }
            //数据对比
            if (ObjectUtils.isEmpty(totalApsBomList) && ObjectUtils.isEmpty(totalErpBomList)) {
                return resultList;
            } else if (ObjectUtils.isNotEmpty(totalApsBomList) && ObjectUtils.isEmpty(totalErpBomList)) {
                for (Map<String, Object> apsBom : totalApsBomList) {
                    OrderCompareVo vo = new OrderCompareVo();
                    this.fixApsCompareVo(vo, apsBom);
                    resultList.add(vo);
                }
            } else if (ObjectUtils.isEmpty(totalApsBomList) && ObjectUtils.isNotEmpty(totalErpBomList)) {
                for (Map<String, Object> erpBom : totalErpBomList) {
                    OrderCompareVo vo = new OrderCompareVo();
                    this.fixErpCompareVo(vo, erpBom);
                    resultList.add(vo);
                }
            } else {
                Map<String, List<Map<String, Object>>> apsDetailMap = totalApsBomList.stream().collect(Collectors.groupingBy(e -> e.get("erp_code").toString() + e.get("mater_code").toString()));
                Map<String, List<Map<String, Object>>> erpDetailMap = totalErpBomList.stream().collect(Collectors.groupingBy(e -> e.get("material_code").toString() + e.get("graph_no").toString()));
                for (Map<String, Object> apsBom : totalApsBomList) {
                    OrderCompareVo vo = new OrderCompareVo();
                    String string = apsBom.get("erp_code").toString() + apsBom.get("mater_code").toString();
                    List<Map<String, Object>> erpMaps = erpDetailMap.get(apsBom.get("erp_code").toString() + apsBom.get("mater_code").toString());
                    if (ObjectUtils.isNotEmpty(erpMaps)) {

                        Map<String, Object> erpMap = erpMaps.get(0);
                        String apsSize = apsBom.get("standards").toString();
                        Integer apsTotalCount = new BigDecimal(apsBom.get("totalCount").toString()).intValue();
                        String apsOrderNo = apsBom.get("work_order_code").toString();
                        String erpSize = erpMap.get("grade").toString();
                        Integer erpTotalCount = new BigDecimal(erpMap.get("req_qty").toString()).intValue();
                        String erpOrderNo = erpMap.get("work_order_code").toString();

                        if (!apsSize.equals(erpSize) || !apsTotalCount.equals(erpTotalCount)) {
                            this.fixApsCompareVo(vo, apsBom);
                            this.fixErpCompareVo(vo, erpMap);
                            resultList.add(vo);
                        }
                    } else {
                        this.fixApsCompareVo(vo, apsBom);
                        resultList.add(vo);
                    }

                }
                for (Map<String, Object> erpBom : totalErpBomList) {
                    OrderCompareVo vo = new OrderCompareVo();
                    List<Map<String, Object>> apsMaps = apsDetailMap.get(erpBom.get("material_code").toString() + erpBom.get("graph_no").toString());
                    if (ObjectUtils.isEmpty(apsMaps)) {
                        this.fixErpCompareVo(vo, erpBom);
                        resultList.add(vo);
                    }
                }
            }

        }
        return resultList;
    }
    /**
     * @Description: aps订单与aps套料
     *
     * @author: hejiahui
     * @since: 2024/9/13 10:46
     */
    private List<OrderCompareVo> compareApsNestOrder(List<String> topOrderList, List<Map<String, Object>> apsOrderBomList, List<Map<String, Object>> nestOrderList) {
        List<OrderCompareVo> resultList = new ArrayList<>();
        Map<String, List<Map<String, Object>>> apsMaterCodeMap = apsOrderBomList.stream().collect(Collectors.groupingBy(e -> e.get("mater_code").toString()));
        Map<Integer, List<Map<String, Object>>> apsBomIdMap = apsOrderBomList.stream().filter(e -> e.get("pid") != null ).collect(Collectors.groupingBy(e -> (Integer) e.get("pid")));
        List<Map<String, Object>> totalApsBomList = new ArrayList<>();
        for (String order : topOrderList) {
            List<Map<String, Object>> aps = apsMaterCodeMap.get(order);
            if (ObjectUtils.isEmpty(aps)) {
                throw new RuntimeException("数据异常:未找到" + order + "的数据！！！");
            } else if (aps.size() > 1) {
                throw new RuntimeException(order + "的数据" + "找到多条！！！");
            }
            //获取aps全量bom
//            totalApsBomList.add(aps.get(0));
            List<Map<String, Object>> apsCheckList = new ArrayList<>();
            apsCheckList.add(aps.get(0));
            while (apsCheckList.size() > 0) {
                Map<String, Object> apsBom = apsCheckList.get(0);
                List<Map<String, Object>> maps = apsBomIdMap.get((Integer) apsBom.get("id"));
                apsCheckList.remove(0);
                if (ObjectUtils.isNotEmpty(maps)) {
                    List<Map<String, Object>> partList = maps.stream().filter(e -> e.get("mater_type") != null).filter(e -> e.get("mater_type").toString().equals("Platepart")).collect(Collectors.toList());
                    totalApsBomList.addAll(partList);
                    apsCheckList.addAll(maps);
                }
            }
        }
        //数据对比
        if (ObjectUtils.isEmpty(totalApsBomList) && ObjectUtils.isEmpty(nestOrderList)) {
            return resultList;
        } else if (ObjectUtils.isNotEmpty(totalApsBomList) && ObjectUtils.isEmpty(nestOrderList)) {
            for (Map<String, Object> apsBom : totalApsBomList) {
                OrderCompareVo vo = new OrderCompareVo();
                this.fixApsCompareVo(vo, apsBom);
                resultList.add(vo);
            }
        } else if (ObjectUtils.isEmpty(totalApsBomList) && ObjectUtils.isNotEmpty(nestOrderList)) {
            for (Map<String, Object> nestOrder : nestOrderList) {
                OrderCompareVo vo = new OrderCompareVo();
                this.fixNestCompareVo2(vo, nestOrder);
                resultList.add(vo);
            }
        } else {
            Map<String, List<Map<String, Object>>> apsDetailMap = totalApsBomList.stream().collect(Collectors.groupingBy(e -> e.get("erp_code").toString() + e.get("plm_id").toString()));
            Map<String, List<Map<String, Object>>> nestDetailMap = nestOrderList.stream().collect(Collectors.groupingBy(e -> e.get("erp_code").toString() + e.get("plm_id")));
            for (Map<String, Object> apsBom : totalApsBomList) {
                OrderCompareVo vo = new OrderCompareVo();
                List<Map<String, Object>> nestMaps = nestDetailMap.get(apsBom.get("erp_code").toString() + apsBom.get("plm_id").toString());
                if (ObjectUtils.isNotEmpty(nestMaps)) {
                    Map<String, Object> nestMap = nestMaps.get(0);

                    String apsMaterial = this.sendNestMater(apsBom.get("standards"), apsBom.get("texture"));
                    Integer apsThick = new BigDecimal(apsBom.get("standards").toString().split("δ")[1]).intValue();
                    Integer apsTotalCount = new BigDecimal(apsBom.get("totalCount").toString()).intValue();

                    String nestMaterial = nestMap.get("texture").toString();
                    Integer nestThick = new BigDecimal(nestMap.get("thick_ness").toString()).intValue();
                    Integer nestTotalCount = new BigDecimal(nestMap.get("totalCount").toString()).intValue();

                    if (!MaterialUtils.compare(apsBom.get("standards").toString(),nestMap.get("texture").toString() + "δ" + new BigDecimal(nestMap.get("thick_ness").toString()).intValue()) || !apsThick.equals(nestThick) || !apsTotalCount.equals(nestTotalCount)) {
                        this.fixApsCompareVo(vo, apsBom);
                        this.fixNestCompareVo2(vo, nestMap);
                        resultList.add(vo);
                    }
                } else {
                    this.fixApsCompareVo(vo, apsBom);
                    resultList.add(vo);
                }
            }
            for (Map<String, Object> nestBom : nestOrderList) {
                OrderCompareVo vo = new OrderCompareVo();
                List<Map<String, Object>> apsMaps = apsDetailMap.get(nestBom.get("erp_code").toString() + nestBom.get("plm_id").toString());
                if (ObjectUtils.isEmpty(apsMaps)) {
                    this.fixNestCompareVo2(vo, nestBom);
                    resultList.add(vo);
                }
            }
        }
        return resultList;
    }
    /**
     * @Description: aps套料与ERP对比
     *
     * @author: hejiahui
     * @since: 2024/9/14 15:31
     */
    private List<OrderCompareVo> compareNestErpOrder(List<String> topOrderList, List<Map<String, Object>> nestOrderList, List<Map<String, Object>> erpOrderBomList) {
        List<OrderCompareVo> resultList = new ArrayList<>();
        Map<String, List<Map<String, Object>>> erpGraphNoMap = erpOrderBomList.stream().collect(Collectors.groupingBy(e -> e.get("graph_no").toString()));
        Map<String, List<Map<String, Object>>> erpMaterCodeMap = erpOrderBomList.stream().filter(e -> e.get("pm_code") != null).collect(Collectors.groupingBy(e -> e.get("pm_code").toString()));
        List<Map<String, Object>> totalErpBomList = new ArrayList<>();
        for (String order : topOrderList) {
            List<Map<String, Object>> erp = erpGraphNoMap.get(order);
            if (ObjectUtils.isEmpty(erp)) {
                throw new RuntimeException("数据异常:未找到" + order + "的数据！！！");
            } else if (erp.size() > 1) {
                throw new RuntimeException(order + "的数据" + "找到多条！！！");
            }
            //获取erp全量bom
            totalErpBomList.add(erp.get(0));
            List<Map<String, Object>> erpCheckList = new ArrayList<>();
            erpCheckList.add(erp.get(0));
            while (erpCheckList.size() > 0) {
                Map<String, Object> erpBom = erpCheckList.get(0);
                List<Map<String, Object>> maps = erpMaterCodeMap.get(erpBom.get("material_code").toString());
                erpCheckList.remove(0);
                if (ObjectUtils.isNotEmpty(maps)) {
                    List<Map<String, Object>> partList = maps.stream().filter(e -> e.get("spec").toString().contains("δ")).collect(Collectors.toList());
                    totalErpBomList.addAll(partList);
                    erpCheckList.addAll(maps);
                }
            }
        }
        //数据对比
        if (ObjectUtils.isEmpty(nestOrderList) && ObjectUtils.isEmpty(totalErpBomList)) {
            return resultList;
        } else if (ObjectUtils.isNotEmpty(nestOrderList) && ObjectUtils.isEmpty(totalErpBomList)) {
            for (Map<String, Object> nestOrder : nestOrderList) {
                OrderCompareVo vo = new OrderCompareVo();
                this.fixNestCompareVo1(vo, nestOrder);
                resultList.add(vo);
            }
        } else if (ObjectUtils.isEmpty(nestOrderList) && ObjectUtils.isNotEmpty(totalErpBomList)) {
            for (Map<String, Object> erpBom : totalErpBomList) {
                OrderCompareVo vo = new OrderCompareVo();
                this.fixErpCompareVo(vo, erpBom);
                resultList.add(vo);
            }
        } else {
            Map<String, List<Map<String, Object>>> nestDetailMap = nestOrderList.stream().collect(Collectors.groupingBy(e -> e.get("erp_code").toString() + e.get("plm_id")));
            Map<String, List<Map<String, Object>>> erpDetailMap = totalErpBomList.stream().filter(e -> e.get("plm_id") != null).collect(Collectors.groupingBy(e -> e.get("material_code").toString() + e.get("plm_id").toString()));
            for (Map<String, Object> nestBom : nestOrderList) {
                OrderCompareVo vo = new OrderCompareVo();
                List<Map<String, Object>> erpMaps = erpDetailMap.get(nestBom.get("erp_code").toString() + nestBom.get("plm_id").toString());
                if (ObjectUtils.isNotEmpty(erpMaps)) {
                    Map<String, Object> erpMap = erpMaps.get(0);
                    String nestMaterial = nestBom.get("texture").toString() + "δ" + new BigDecimal(nestBom.get("thick_ness").toString()).intValue();
                    Integer nestThick = new BigDecimal(nestBom.get("thick_ness").toString()).intValue();
                    Integer nestTotalCount = new BigDecimal(nestBom.get("totalCount").toString()).intValue();

                    String erpMaterial = erpMap.get("grade").toString();
                    Integer erpThick = new BigDecimal(erpMap.get("grade").toString().split("δ")[1]).intValue();
                    Integer erpTotalCount = new BigDecimal(erpMap.get("req_qty").toString()).intValue();

                    if (!nestMaterial.equals(erpMaterial) || !nestThick.equals(erpThick) || !nestTotalCount.equals(erpTotalCount)) {
                        this.fixNestCompareVo1(vo, nestBom);
                        this.fixErpCompareVo(vo, erpMap);
                        resultList.add(vo);
                    }
                } else {
                    this.fixNestCompareVo1(vo, nestBom);
                    resultList.add(vo);
                }
            }
            for (Map<String, Object> erpBom : totalErpBomList) {
                if (erpBom.get("plm_id") != null) {
                    OrderCompareVo vo = new OrderCompareVo();
                    List<Map<String, Object>> nestMaps = nestDetailMap.get(erpBom.get("material_code").toString() + erpBom.get("plm_id").toString());
                    if (ObjectUtils.isEmpty(nestMaps)) {
                        this.fixErpCompareVo(vo, erpBom);
                        resultList.add(vo);
                    }
                }
            }
        }

        return resultList;
    }
    /**
     * @Description: 获取材质
     *
     * @author: hejiahui
     * @since: 2024/9/15 9:26
     */
    private String sendNestMater(Object standards, Object texture) {

        String[] split = standards.toString().split("δ");
        if (texture == null || !StringUtils.hasText(texture.toString())) {
            return split[0].trim();//材质
        } else {
            return texture.toString();//材质
        }
    }
    /**
     * @Description: 完善aps的OrderCompareVo
     *
     * @author: hejiahui
     * @since: 2024/9/13 14:51
     */
    private void fixApsCompareVo(OrderCompareVo vo, Map<String, Object> apsBom) {
        try {
            vo.setConstructNo1(apsBom.get("order_code").toString());
            vo.setWorkOrderCode1(apsBom.get("work_order_code").toString());
            if ((apsBom.get("plm_id") != null)) {
                vo.setPlmid1(apsBom.get("plm_id").toString());
            }
            vo.setMaterial1(apsBom.get("erp_code").toString());
            vo.setMaterialName1(apsBom.get("mater_name").toString());
            vo.setSize1(apsBom.get("standards").toString());
            vo.setCount1(apsBom.get("totalCount").toString());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
    /**
     * @Description: 完善erp的OrderCompareVo
     *
     * @author: hejiahui
     * @since: 2024/9/13 14:51
     */
    private void fixErpCompareVo(OrderCompareVo vo, Map<String, Object> erpBom) {
        try {
            vo.setConstructNo2(erpBom.get("order_code").toString());
            vo.setWorkOrderCode2(erpBom.get("work_order_code").toString());
            if ((erpBom.get("plm_id") != null)) {
                vo.setPlmid2(erpBom.get("plm_id").toString());
            }
            vo.setMaterial2(erpBom.get("material_code").toString());
            vo.setMaterialName2(erpBom.get("material_name").toString());
            vo.setSize2(erpBom.get("grade").toString());
            vo.setCount2(erpBom.get("req_qty").toString());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
    /**
     * @Description: 完善erp的OrderCompareVo1
     *
     * @author: hejiahui
     * @since: 2024/9/14 15:38
     */
    private void fixNestCompareVo1(OrderCompareVo vo, Map<String, Object> nestOrder) {
        try {
            vo.setConstructNo1(nestOrder.get("project_id").toString());
            if ((nestOrder.get("work_order_code") != null)) {
                vo.setWorkOrderCode1(nestOrder.get("work_order_code").toString());
            }

            if ((nestOrder.get("plm_id") != null)) {
                vo.setPlmid1(nestOrder.get("plm_id").toString());
            }
            vo.setMaterial1(nestOrder.get("erp_code").toString());
            vo.setMaterialName1(nestOrder.get("mater_name").toString());
            String size = nestOrder.get("texture").toString() + "δ" + new BigDecimal(nestOrder.get("thick_ness").toString()).intValue();
            vo.setSize1(size);
            vo.setCount1(nestOrder.get("totalCount").toString());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
    /**
     * @Description: 完善erp的OrderCompareVo2
     *
     * @author: hejiahui
     * @since: 2024/9/14 14:34
     */
    private void fixNestCompareVo2(OrderCompareVo vo, Map<String, Object> nestOrder) {
        try {
            vo.setConstructNo2(nestOrder.get("project_id").toString());
            if ((nestOrder.get("work_order_code") != null)) {
                vo.setWorkOrderCode2(nestOrder.get("work_order_code").toString());
            }

            if ((nestOrder.get("plm_id") != null)) {
                vo.setPlmid2(nestOrder.get("plm_id").toString());
            }
            vo.setMaterial2(nestOrder.get("erp_code").toString());
            vo.setMaterialName2(nestOrder.get("mater_name").toString());
            String size = nestOrder.get("texture").toString() + "δ" + new BigDecimal(nestOrder.get("thick_ness").toString()).intValue();
            vo.setSize2(size);
            vo.setCount2(nestOrder.get("totalCount").toString());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }
}
